package models;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import play.Logger;
import play.db.jpa.GenericModel;
import play.db.jpa.JPA;
import utils.ExceptionUtil;

/**
 * The persistent class for the channelpermissions database table.
 * 
 */
@Entity
@Table(name = "channelpermissions")
@NamedQueries({
	@NamedQuery(name="Channelpermissions.findBy_orgcode", query="SELECT cp FROM Channelpermissions cp WHERE cp.orgcode = :orgcode")
})
public class Channelpermissions extends GenericModel implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long id;
	
	public String orgcode;
	public String publickey;
	public String privatekey;
	public boolean iscansell;
	public boolean iscanreturn;
	public boolean iscancancel;
	public double quota;
	
	@Temporal(TemporalType.DATE)
	public Date effectivestartdate;
	@Temporal(TemporalType.DATE)
	public Date effectiveenddate;
	
	public int licensestate;
	public int balancecycle;
	public double usefulquota;
	public double bysellamount;
	public boolean instation;
	public double servicefee;
	public boolean isactive;
	public String ordernopre;
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date createtime;
	
	public Integer createby;
	
	public Integer updateby;
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date updatetime;

	/**
	 * 根据机构编码查询机构信息
	 * 该查询不使用缓存为实时查询
	 * @param code
	 * @param flag 是否输出异常信息
	 * @return
	 */
	public static Channelpermissions findBy_orgcode(String orgcode,boolean flag){
		try{
			Channelpermissions cp = JPA.em()
					.createNamedQuery("Channelpermissions.findBy_orgcode", Channelpermissions.class)
					.setParameter("orgcode", orgcode).getSingleResult();
			return cp;
		}catch(Exception e){
			if(flag){
				Logger.log4j.error(ExceptionUtil.getMessageHead(null), e);
			}
			return null;
		}
	}

}